/**
 * @author Arty
 * @modified 24.02.2012
 * @version 1.0 description: on load project
 * 
 */
$(document).ready(function() {
	// fadeIn content
	$("body").fadeIn();
});

/**
 * GLOBAL VARS/OJECTS
 */
var ContentManager = new ContentManager();

/**
 * @function ContentManager description: used to load content on pages
 */

function ContentManager() {
	var _this = this;
	this.errorMsg = "ContentManager, settings error!";

	this.load = function(settings) {
		if (settings == undefined)
			return alert(this.errorMsg);
		if (settings.path == undefined)
			return alert(this.errorMsg);
		if (settings.loadTo == undefined)
			return alert(this.errorMsg);

		$.ajax({
			url : settings.path,
			beforeSend : function() {
				$(settings.loadTo).html("");
			},
			success : function(data) {
				$(settings.loadTo).html(data);
			},
			error : function() {
				var $a = $("a").attr(href, function() {
					_this.load(settings);
				});
				$(settings.loadTo)
						.html("Error loading content!\n Retry: " + $a);
			}
		});
	};
}

/**
 * @function CallManager description: function used to call Struts2 actions
 */
// call function, used for all requests type=json
function CallManager(settings) {
	var body = null;
	var url = "";
	var params = "";
	var _dataType = "json";
	var responseFunc = null;
	if (settings == undefined)
		return alert("call function, settings error!");
	if (settings.url != undefined)
		url = settings.url;
	if (settings.params != undefined)
		params = settings.params;
	if (settings.dataType != undefined)
		_dataType = settings.dataType;
	if (settings.func != undefined) {
		responseFunc = function(data) {
			settings.responseFunc;
		};
	}
	if (settings.body != undefined)
		body = settings.body;
	$.ajax({
		url : url,
		type : "POST",
		data : params,
		dataType : _dataType,
		beforeSend : function() {
		},
		success : function(data) {
			if (settings.responseFunc == undefined)
				return data;
			// jsonToStr(data);
			settings.responseFunc(data);
		},
		error : function(e) {
			$(body).html(
					"Error!\n Code: " + e.status + "\n Msg: " + e.statusText);
		}
	});
}
